Code stempels

3.1

terug

/*lacework of lines from Lauwerier graphics&Fractals Schoonhoven, 1994
chapter 3.1 translated by J.G.van Unnik*/
//name:WEB
float N=10;
int[] C ={#000000,#0000AA,#00AA00,#00AAAA,#AA0000,#AA00AA,#AA5500,#AAAAAA, #555555,#5555FF,#55FF55,#55FFFF,#FF5555,#FF55FF,#FFFF55,#FFFFFF};
//EGA color numbers
int cycle=0,cmax=3;
void setup(){
size (300,200);
background(0);
stroke(255);
smooth();
noLoop();
}
void draw(){
for(float i=0;i<=N;i=i+1){
for(float j=0;j<=N;j=j+1){
int D=int(abs(i-j));
float x1=width*i/N,y1=200,x2=width*j/N,y2=0;
if(D % 2==1){
stroke(C[D]);
line(x1,y1,x2,y2);
}
}
}
}
void mousePressed(){
cycle=cycle+1;
if(cycle==0){N=10;}
else if(cycle==1){N=13;}
else if(cycle==2){N=16;}
else{cycle=0;N=10;}
background(0);
redraw();
}

2.2

terug

void setup(){
noLoop();
size (200,200);
background(255);
stroke(0);
noFill();
}

void draw(){
for(int m=0;m<10;m++){ //for each row
for(int n=0;n<9;n++){ //for each column
drawCat(n*24,m*24); //calls the sub drawCat
}
}
}

void drawCat(int x,int y){
pushMatrix(); //stores the XY matrix
translate(x,y); //sets p(x,y) to 0,0)
float[]xCat={0,-2,0,0,8,18,24,24,22,24,18,6,0,4,3,5,7,8,8,4,12,12,13,15,17,16,12,5,15,10,10,10,5};
float[]yCat={0,-8,-16,-24,-18,-18,-24,-16,-8,0,6,6,0,-4,-6,-8,-8,-7,-4,-4,-4,-7,-8,-8,-6,-4,-4,-2,-2,-1,1,-1,-2};
beginShape();
for (int i=0;i<13;i++){
vertex(xCat[i],yCat[i]); //draws the shape "Cat"
}
endShape();
beginShape();
for (int i=13;i<20;i++){
vertex(xCat[i],yCat[i]);
}
endShape();
beginShape();
for (int i=20;i<27;i++){
vertex(xCat[i],yCat[i]);
}
endShape();
beginShape();
for (int i=27;i<33;i++){
vertex(xCat[i],yCat[i]);
}
endShape();

popMatrix(); //restores the original XY matrix
}

Stempels van Truchet

terug

/*from H.A. Lauwerier Graphics&Fractals, 1994 program TRUCHET translated into
Processing by J.G.van Unnik, 2010*/
void setup(){
size(400,400);
background(255);
stroke(0);
strokeWeight(2);
smooth();
noFill();
rect(0,0,399,399);
noLoop();

void draw(){
for(int m=0;m<10;m++){    //for each row
for(int n=0;n<10;n++){  //for each column
float r=random(1);
if (r<.5){
stamp1(m*40,n*40);    //calls the sub stamp1
}
else{
stamp2(m*40,n*40);
}
}
}
}

void stamp1(int x,int y){
pushMatrix(); //stores the XY matrix
translate(x,y); //sets p(x,y) to 0,0)
arc(0,0,40,40,0,PI-HALF_PI);
arc(40,40,40,40,PI,PI+HALF_PI);
popMatrix();
}
void stamp2(int x,int y){
pushMatrix(); //stores the XY matrix
translate(x,y); //sets p(x,y) to 0,0)
arc(40,0,40,40,PI-HALF_PI,PI);
arc(0,40,40,40,PI+HALF_PI,TWO_PI);
popMatrix();
}
void mousePressed(){
background(255);
rect(0,0,399,399);
redraw();
}

2.3

terug

/* circle drawing after H.A.Lauwerier Spelen met graphics
en Fractals Schoonhoven, 1994 ISBN 90-395-0092-4 with
80 programs in QBasic and PowerBasic, adapted by J.G.van Unnik
de curve results from two circular movements with different
radius and phase*/
int t, cycle=1;
float T=0.0; //loop count
void setup() {
size(200,200); // Set the size of the windoNw
background(255);
stroke(0);
smooth();
}
void draw() {
float A=PI; //A is the phase difference
float R=.6; // R is de ratio of the radiuses of the two circles
float X=60*cos(T);
float Y=60*sin(T);
float X1=100+X+R*60*cos(A*T);
float Y1=100+Y+R*60*sin(A*T);
point (X1,Y1);
T=T+.02;
}
void mousePressed(){
cycle=cycle+1;
if(cycle>1){
cycle=0;
noLoop();}
else{loop();}
}

2.4

terug

int M=4,cycle=0;

void setup(){
size(200,200);
background(255);
stroke(0);
strokeWeight(.05);
fill(0);
}
void draw(){
background(255);
scale(15,-40);
translate(6.5,-2.5);
float[] B= new float[M];
float X=0,S=0,X1,S1;
int JMAX=1000;
for(int i=1;i<M;i=i+1){
B[i]=1/float(i);}
line(-2*PI,0,2*PI,0);
for(int J=0;J<=JMAX;J++){
X1=-2*PI+4*PI*J/JMAX;
S1=0;
for(int k=1;k<M;k++){
S1=S1+B[k]*sin(k*X1);
}
if(J==0){X=X1;S=S1;}
else{
line(X,S,X1,S1);
X=X1;
S=S1;
}
}
}
void mousePressed(){
cycle=cycle+1;
if (cycle==1){M=8;}
else if (cycle==2){M=12;}
else if (cycle==3){M=20;}
else if (cycle==4){M=90;}
else {cycle=0;M=4;}
}

2.5

terug

/*from H.A. Lauwerier Graphics&Fractals, 1994 program LISSAX translated into
Processing by J.G.van Unnik, 2010*/

float T=0; //loop number
float H=0.04; //the increment of the loop number
float A=70; //the size of the figure
float M=1, N=1; //the rotational frequencies
float F=.5; //the phase shift
int k;
void setup() {
size(200,200); // Sets the size of the window
background(255);
stroke(0);
strokeWeight(2);
smooth();
}
void draw() {
float S=N/M;
float X=100+A*sin(T);
float Y=100+A*sin(S*T+F);
point(X,Y);
T=T+H;
}
void mousePressed(){
noLoop();
k = k+1;
switch(k) {
case 1:
M=1;N=2;F=.5;
break;
case 2:
M=1;N=3;F=.75;H=.02;
break;
case 3:
M=1;N=4;F=0;
break;
case 4:
M=1;N=8;F=.2;
break;
default:
M=1;N=1;F=.5;H=.04;k=0;
}
background(255);
loop(); }

terug